package test;
import java.awt.event.ActionEvent;
import java.util.Random;

import javax.swing.AbstractAction;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.LayoutStyle;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import divination.yijing.DivinationCoins;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
@SuppressWarnings("serial")
public class JFdiv extends javax.swing.JFrame {
	private JButton divButton;
	private JTextArea gua;
	private JTextArea description;
	private AbstractAction divAction;
	private JScrollPane jScrollPane1;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFdiv inst = new JFdiv();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public JFdiv() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			GroupLayout thisLayout = new GroupLayout((JComponent)getContentPane());
			getContentPane().setLayout(thisLayout);
			this.setTitle("\u6613\u7d93\u5360\u535c");
			this.setLocale(new java.util.Locale("zh", "TW"));
			{
				divButton = new JButton();
				divButton.setText("Go");
				divButton.setAction(getDivAction());
				divButton.setSize(60, 20);
				divButton.setLocale(new java.util.Locale("zh", "TW"));
			}
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
				.addContainerGap()
				.addComponent(divButton, GroupLayout.PREFERRED_SIZE, 18, GroupLayout.PREFERRED_SIZE)
				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
				.addComponent(getDescription(), GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 0, GroupLayout.PREFERRED_SIZE)
				.addComponent(getJScrollPane1(), 0, 197, Short.MAX_VALUE));
			thisLayout.setHorizontalGroup(thisLayout.createParallelGroup()
				.addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				    .addComponent(divButton, GroupLayout.PREFERRED_SIZE, 84, GroupLayout.PREFERRED_SIZE)
				    .addGap(380))
				.addComponent(getDescription(), GroupLayout.Alignment.LEADING, 0, 464, Short.MAX_VALUE)
				.addGroup(thisLayout.createSequentialGroup()
				    .addComponent(getJScrollPane1(), 0, 464, Short.MAX_VALUE)
				    .addGap(6)));
			pack();
			this.setSize(480, 300);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private AbstractAction getDivAction() {
		if(divAction == null) {
			divAction = new AbstractAction("\u5360\u535c", null) {
				public void actionPerformed(ActionEvent evt) {
					Random rd = new Random();
					String[] guas = divinationCoins(rd);
					gua.setText(guas[0] + "\n\n\n" + guas[1]);
				}
			};
		}
		return divAction;
	}
	
    public String[] divinationCoins(Random rd){
    	// Divination
    	DivinationCoins d1 = new DivinationCoins(rd);
    	// Form output strings
    	String[] gua = new String[2];
    	gua[0] = d1.original.getName() + "\n" + 
    			 d1.original.toString()+ "\n" + 
    			 d1.original.getClassicInterpretation()+ "\n" + 
    			 d1.original.getModernInterpretation();
    	gua[1] = d1.varied.getName() + "\n" + 
		 		 d1.varied.toString()+ "\n" + 
		 		 d1.varied.getClassicInterpretation()+ "\n" + 
		 		 d1.varied.getModernInterpretation();
    	// Return results
    	return(gua);
    }
    
    private JTextArea getDescription() {
    	if(description == null) {
    		description = new JTextArea();
    		description.setText("\u91d1\u9322\u5366\u59cb\u65bc\u6f22\u671d\uff0c\u4e43\u53d6\u9285\u9322\u64f2\u4e09\u6b21\u70ba\u4e00\u723b\uff0c\u53d6\u6578\u591a\u8005\u5b9a\u9670\u967d\uff0c\u4ee5\u4e09\u8005\u540c\u5426\u5b9a\u8001\u5c11\u3002\n\u516d\u723b\u64f2\u7562\u6210\u4e8c\u5366\uff0c\u672c\u5366\u53ef\u4f5c\u8fd1\u6cc1\u89e3\uff0c\u800c\u8b8a\u5366\u70ba\u672a\u4f86\u9577\u671f\u4e4b\u9810\u6e2c\u3002");
    		description.setLocale(new java.util.Locale("zh", "TW"));
    	}
    	return description;
    }
    
    private JScrollPane getJScrollPane1() {
    	if(jScrollPane1 == null) {
    		jScrollPane1 = new JScrollPane();
    		jScrollPane1.setLocale(new java.util.Locale("zh", "TW"));
    		{
    			gua = new JTextArea();
    			jScrollPane1.setViewportView(gua);
    			gua.setLocale(new java.util.Locale("zh", "TW"));
    		}
    	}
    	return jScrollPane1;
    }

}
